from fastapi import APIRouter, HTTPException
from app.models.schemas import AuditRequest, AuditResult, AuditFeedback
from app.services.audit_service import audit_service
import logging

logger = logging.getLogger(__name__)

router = APIRouter()

@router.post("/audit", response_model=AuditResult)
async def audit_content(request: AuditRequest):
    """审核帖子内容"""
    try:
        logger.info(f"收到审核请求，帖子ID: {request.post_id}")
        result = audit_service.audit_content(request)
        return result
    except Exception as e:
        logger.error(f"审核失败: {str(e)}")
        raise HTTPException(status_code=500, detail=f"审核处理失败: {str(e)}")

@router.post("/feedback", response_model=dict)
async def submit_feedback(feedback: AuditFeedback):
    """提交审核反馈"""
    try:
        logger.info(f"收到反馈请求，帖子ID: {feedback.post_id}")
        success = audit_service.save_feedback(feedback)
        if success:
            return {"status": "success", "message": "反馈已保存"}
        else:
            raise HTTPException(status_code=500, detail="保存反馈失败")
    except Exception as e:
        logger.error(f"保存反馈失败: {str(e)}")
        raise HTTPException(status_code=500, detail=f"保存反馈失败: {str(e)}") 